<template>
    <el-dialog title="关闭检验批" :close-on-click-modal="false" :visible.sync="visible" :append-to-body="true"
        class="SHZY-dialog SHZY-dialog_center" lock-scroll width="600px">
        <el-form ref="elForm" :model="dataForm" size="small" label-width="50px" label-position="right" :rules="rules">
            <el-form-item label="原因" prop="closeDes">
                <el-input v-model="dataForm.closeDes" show-word-limit :style='{ "width": "100%" }' type='textarea'
                    :autosize='{ "minRows": 4, "maxRows": 4 }' maxlength='500'>
                </el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="visible = false">{{ $t('common.cancelButton') }}</el-button>
            <el-button :loading="btnLoading" type="primary" @click="dataFormSubmit()">确 定</el-button>
        </span>
    </el-dialog>
</template>
    
<script>
import { closeIpqcInspectionlot } from '@/api/q1/business/ipqcInspectionLot'

export default {
    data() {
        return {
            visible: false,
            btnLoading: false,
            dataForm: {
                id: "",
                closeDes: "",
            },
            rules: {
                closeDes: [
                    { required: true, message: '请填写原因', trigger: '"blur"' },
                ]
            }
        }
    },
    methods: {
        init(id) {
            this.dataForm.id = id || 0
            this.dataForm.closeDes = ""
            this.visible = true
        },
        dataFormSubmit() {
            this.$refs['elForm'].validate((valid) => {
                if (valid) {
                    this.btnLoading = true;
                    closeIpqcInspectionlot(this.dataForm).then((res) => {
                        this.btnLoading = false;
                        this.$message({
                            message: res.msg,
                            type: 'success',
                            duration: 1000,
                            onClose: () => {
                                this.visible = false
                                this.$emit('refresh', true)
                            }
                        })
                    }).catch((res) => {
                        this.btnLoading = false;
                    })
                }
            })
        }
    }
}
</script>